/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

		package menu;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import model.Student;

import dao.StudentDao;
public class Add_Menu {
	JFrame add_menu;
	JPanel p1,p2,p11,p12,p13,p14,p15,p16;
	JLabel l1,l2,l3,l4,l5,l6;
	JTextField t1,t2,t3,t4,t5,t6;
	JButton b_ok,b_cancel;
	
	public void student_add(){
		add_menu = new JFrame("录入学生信息");
		p1 = new JPanel();
		p2 = new JPanel();
		p11 = new JPanel();
		p12 = new JPanel();
		p13 = new JPanel();
		p14 = new JPanel();
		p15 = new JPanel();
		p16 = new JPanel();
		p1.setLayout(new GridLayout(6,1));
		l1 = new JLabel("    学     号：");
		l2 = new JLabel("    姓     名：");
		l3 = new JLabel("   性     别：");
		l4 = new JLabel("出生日期：");
		l5 = new JLabel("院系代码：");
		l6 = new JLabel("所在班级：");
		t1 = new JTextField(16);
		t2 = new JTextField(16);
		t3 = new JTextField(16);
		t4 = new JTextField(16);
		t5 = new JTextField(16);
		t6 = new JTextField(16);
		p11.add(l1);
		p11.add(t1);
		p12.add(l2);
		p12.add(t2);
		p13.add(l3);
		p13.add(t3);
		p14.add(l4);
		p14.add(t4);
		p15.add(l5);
		p15.add(t5);
		p16.add(l6);
		p16.add(t6);
		p1.add(p11);
		p1.add(p12);
		p1.add(p13);
		p1.add(p14);
		p1.add(p15);
		p1.add(p16);
		p2.add(b_ok = new JButton("确定"));
		p2.add(b_cancel = new JButton("取消"));
		b_ok.addActionListener(new Monitor2());
		b_cancel.addActionListener(new Monitor2());
		add_menu.add(p1,BorderLayout.NORTH);
		add_menu.add(p2,BorderLayout.SOUTH);
		add_menu.setBounds(400,200,400,300);
		add_menu.setVisible(true);
	}
	public static void main(String args[]){
		new Add_Menu().student_add();
	}
	private class Monitor2 implements ActionListener{
	    	public void actionPerformed(ActionEvent e) {
				if(e.getActionCommand().equals("取消")){
					add_menu.setVisible(false); 
					new Son_menu().studentmenu();
					}
				if(e.getActionCommand().equals("确定")){
					Student s = new Student();
					s.setId(Integer.parseInt(t1.getText()));
					s.setName(t2.getText());
					s.setSex(t3.getText());
					s.setBorn_date(t4.getText());
					s.setDepart_id(t5.getText());
					s.setClass_name(t6.getText());
					new StudentDao().addInfo(s);
					add_menu.setVisible(false); 
					new Son_menu().studentmenu();
				}
	    	}
	}
}


